<?php
// 获取订单信息列表,
require_once $this->website['path']['action'] . '/app/token.php';
$uid = $basic['uid'];

$json = array('status' => 'ok', 'msg' => 'ok', 'data' => false);

// 订单种类 -1全部订单 0未付款 1待发货 2待收货 3待评论 4待评价
$sta = (int) fn_post('sta', -1);
$page = fn_post('page', 1);
$sys = fn_configura($this->website, 'sys');

$this->website['class']['db']
	->table('product_order')
	->page($page)
	->num($sys['pagingnum'])
	->order("id desc");
if ($sta === -1) {
	$this->website['class']['db']->where('uid=? and fid=0', $uid);
} else {
	$this->website['class']['db']->where('uid=? and fid=0 and sta=?', $uid, $sta);
}
$json['sta'] = $sta;
$paging = $this->website['class']['db']->paging();
foreach ($paging['data'] as &$v) {
	$v['params'] = json_decode($v['params'], 1);

	// 商品购买参数---获取商品信息
	foreach ($v['params'] as &$vv) {
		$vv['product'] = $this->website['class']['db']
			->table('product')
			->field('uid', 'tit', 'image')
			->where('id=?', $vv['pid'])
			->one();
		// 取商店信息-只需一次
		if (!($v['shop'] ?? false)) {
			$v['shop'] = $this->website['class']['db']
				->table('shops')
				->field('id', 'tit', 'image')
				->where('id=?', $vv['product']['uid'])
				->one();
		}
	}
}

$json['data'] = $paging;

$this->json_encode_encrypt($json);